<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/28/028
 * Time: 17:31
 */

namespace app\api\model;


use app\api\service\Token;
use app\lib\exception\MemberException;

class Certification extends BaseModel {
    protected $hidden = ['update_time','delete_time', 'create_time'];

    /**
     * 保存用户实名认证信息
     * @param $params
     * @throws MemberException
     */
    public static function save_member_certification($params) {
        $uid = Token::getCurrentUid();

        $certification = self::get(['member_id' => $uid]);
        if ($certification) {
            if ($certification['status'] == 2) {
                throw new MemberException([
                    'msg' => '您已经完成实名认证，请勿重复提交',
                    'errorCode' => 30006
                ]);
            }
            $params['status'] = 1;   // 更新数据  状态重置为1
            $certification->save($params);
        } else {
            $params['member_id'] = $uid;   // 新增数据   添加用户ID
            self::create($params);
        }

    }
}